<%@ page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false"
    pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>历史检索库视图</title>
<%@ include file="/base/base.jsp" %>
<script type="text/javascript">
//表格列数据
var columns=[
	{display:"序号",width:80,render:function(rowData,rowIndex){
		return (parseInt(this.get("page"))-1)*parseInt(this.get("pageSize"))+rowIndex+1;
	}},
	{display:"IP",width:130,name:"ip"},
	{display:"端口",name:"port",width:130},
	{display:"所属区域",name:"area",width:130},
	{display:"响应时间",name:"responseTime",width:130,render:function(rowData){
		return (rowData.responseTime+" ms")
	}},
	{display:"类型",name:"state",width:130,render:function(data){
		var str="";
		switch(data.state){
		case 0:
			str="<label style='color:red'>不可用</label>";
			break;
		case 1:
			str="<label style='color:green'>可用</label>";
			break;
		default:
			str="<label>未知</label>";
		}
		return str;
	}},
	{display:"检索时间",name:"retrieveTimeStr",width:130},
	{display:"检索渠道",name:"retrieveChannelName",width:130}
];
$(function(){
	initTime();
	initGrid();
	search();
});
//初始化日期时间
function initTime(){
	var now=new Date();
	var year=now.getFullYear();
	var month=now.getMonth()+1;
	month=month<10?"0"+month:month+"";
	var date=now.getDate();
	date=date<10?"0"+date:date+"";
	//var start=year+"-"+month+"-"+date+" 00:00:00";
	var hour=now.getHours();
	hour=hour<10?"0"+hour:hour+"";
	var minute=now.getMinutes();
	minute=minute<10?"0"+minute:minute+"";
	var second=now.getSeconds();
	second=second<10?"0"+second:second+"";
	var start=year+"-"+month+"-"+date+" "+(hour-1)+":"+minute+":"+hour;
	var end=year+"-"+month+"-"+date+" "+hour+":"+minute+":"+hour;
	$("#start_retrieveTimeStr").val(start);
	$("#end_retrieveTimeStr").val(end);
	
}

function initGrid(){
	var url="<%=request.getContextPath()%>/monitor/historySearch/search.action";
	$("#ressult_div").ligerGrid({
		height:'100%',
		width:'100%',
		columns:columns,
		enabledSort:false,
		pageSize:50,
		root:"result",//数据集合
		record:"dataSize",//总数据数
		pageParmName:"pageIndex",//页索引
		pagesizeParmName:"pageLen",//页长
		usePager:true,
		dataAction:"server",
		method:"post",
		delayLoad:true,//初始化不加载
		pageSizeOptions:[20,50,100,200],
		url:url
	
	});
	var manager = $("#ressult_div").ligerGetGridManager(); 
	manager.set("height","100%");
}
function search(){
	var ipReg=/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
	if($.trim($("#ip").val())!="" && !ipReg.test($("#ip").val())){
		alert("请输入正确格式的ip");
		return;
	}
	var portrReg=/^\d+$/;
	if($.trim($("#port").val())!="" && !portrReg.test($("#port").val())){
		alert("请输入正确的端口格式");
		return ;
	}
	var startDate=$.trim($("#start_retrieveTimeStr").val()).replace(/-/g,"/");
	var endDate=$.trim($("#end_retrieveTimeStr").val()).replace(/-/g,"/");
	var start=new Date(startDate);
	var end=new Date(endDate);
	if(start.getTime()>end.getTime()){
		 $.ligerDialog.warn('开始时间不能小于结束时间');
		return;
	}
	var url="<%=request.getContextPath()%>/monitor/historySearch/search.action";
	var manager = $("#ressult_div").ligerGetGridManager(); 
    manager.set("newPage",1);
    //alert($('#realTimeSearch_form').serialize());
    //manager.set("data",$('#realTimeSearch_form').serialize());
    //manager.loadServerData($('#realTimeSearch_form').serialize()); 
	manager.set("url",url+"?"+$('#historySearch_form').serialize());
}

function resetSearch(){
	$("#ip").val("");
	$("#port").val("");
	$("#start_retrieveTimeStr").val("");
	$("#end_retrieveTimeStr").val("");
	$("#retrieveChannel").val("");
}

</script>
</head>
<body>

<div class="main">
	<div class="form_body">
		<form id="historySearch_form">
		<div class="form_body_tltle">历史检索库</div>
		<table id="result_table" class="form_table">
			<tr style="height:40px; width:100%;">
			  <td>
				&nbsp;&nbsp;IP&nbsp;&nbsp;<input type="text" name="c.ip" id="ip"/>
				端口&nbsp;&nbsp;<input type="text" name="c.portStr" id="port" style="width:50px;"/>
				检索时间&nbsp;&nbsp;
					<input type="text"
					onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'});"
					readonly="readonly" id="start_retrieveTimeStr" name="c.start_retrieveTimeStr"
					/>
					&nbsp;至
					<input type="text" 
					onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'});"
					readonly="readonly" id="end_retrieveTimeStr" name="c.end_retrieveTimeStr"
					/>
				检索渠道&nbsp;&nbsp;
					<select id="retrieveChannel" name="c.retrieveChannel">
						<option value="">-- 全部 --</option>
						<s:iterator value="channels" id="cur">
							<option value="${cur.code }">${cur.name }</option>
						</s:iterator>
					</select>
				<input type="button"  id="" value="查询" class="" onclick="search()"/>
				<input type="button"  id="" value="清空" class="" onclick="resetSearch()"/>	
			 </td>
			</tr>
		</table>
		</form>
	</div>
	<div style="height:25px"></div>
	<div id="ressult_div" style="height:100%"><span/></div>
</div>
</body>
</html>